home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / STOCHAIN.ASM < prev    next >
Assembly Source File  |  1986-10-24  |  28KB  |  807 lines

  1.                  PAGE 60,132 
  2.                 ;program to chain and form DOS storage blocks
  3.                 ; Usage is: STOCHAIN 
  4.  
  5. sb              SEGMENT AT 0       ;map of storage block header paragraph
  6. sbkind          DB      ' '        ;Type of storage block: M or Z
  7. sbpsp           DW       0         ;PSP segment address
  8. sblength        DW       0         ;SB length in paragraphs
  9. sbfill          DB       11 DUP(0) ;filler
  10.  
  11.  
  12.  
  13.                 ORG      sbkind
  14. pspretint       DW       ?          ;int 20
  15. pspmemsize      DW       ?          ;size of memory in paragraphs
  16. pspresv         DB       ?
  17.                 ORG      5h
  18. pspcalldosfunct DB       ?          ;long call to dos function dispatcher
  19. pspdosfunct     DD       ?          ;IP:CS of dos function dispatcher
  20.                 ORG      0Ah
  21. pspdosterminate DD       ?          ;IP:CS of:dos terminate 
  22.                 ORG      0Eh
  23. pspdosctrlbreak DD       ?          ;         ctrl break address
  24.                 ORG      12h
  25. pspdoscrtclerr  DD       ?          ;         critical error handler
  26.                 ORG      18h
  27. pspdosdefhandle DD       20 dup(?)  ;         DOS 2.0 - 20 file handles
  28.                                     ;         DOS 3.0 - default file handles
  29.                 ORG      2Ch
  30. pspenv          DW       ?          ;segment address of environment
  31.                 ORG      32h
  32. psphandlecount  DW       ?          ;number of handles in table (DOS 3.0)
  33.                 ORG      34h
  34. psphandles      DW       ?          ;offset of handle table in CS (DOS 3.0)
  35.                 ORG      50h
  36. pspdosfunction  DW       ?          ;invoke dos function dispatcher
  37.                 ORG      5Ch
  38. pspfcb1         DB       ?          ;first fcb
  39.                 ORG      6Ch
  40. pspfcb2         DB       ?          ;second fcb
  41.                 ORG      80h
  42. pspparm         DB       ?          ;unformatted paramter area
  43.                 ORG      0FFh
  44. pspend          EQU      $
  45.  
  46. sb              ENDS
  47.  
  48. code_seg        SEGMENT
  49.  
  50.                 ASSUME    CS:code_seg,DS:code_seg,ES:sb
  51.  
  52. cr              equ       13
  53. lf              equ       10
  54.  
  55. myretint        DW       ?          ;int 20
  56.                 ORG      50h
  57. mydosfunction   DW       ?          ;invoke dos function dispatcher
  58.                 ORG       100h
  59.  
  60. code            PROC      far
  61.  
  62.                 jmp       program
  63.                 db        'Copyright 1986 by Arnold B. Krueger GPW MI, 48236'
  64. typestring      proc near 
  65.                 push ax
  66.                 mov  ax,0900h
  67.                 int  21h
  68.                 pop  ax
  69.                 ret
  70. typestring      endp
  71.  
  72. getfirstsb      PROC near       ;get first storage block, ES will point to it
  73.                 PUSH AX
  74.                 PUSH BX
  75.                 MOV  AX,5200h       
  76.                 INT  21h        ;ES:BX points to memory block anchor+2
  77.                 DEC  BX
  78.                 DEC  BX
  79.                 MOV  ES,ES:[BX] ;get first memory block address into ES
  80.                 POP  BX
  81.                 POP  AX
  82.                 RET
  83. getfirstsb      ENDP
  84.  
  85. getnextsb       PROC near
  86.                 PUSH AX
  87.                 MOV  AX,ES             ;get current paragraph
  88.                 ADD  AX,[SBLENGTH]     ;add in number of paragraphs
  89.                 INC  AX                ;add 1 for header
  90.                 MOV  ES,AX             ;set new extra segment address
  91.                 POP  AX
  92.                 RET
  93. getnextsb       ENDP
  94.  
  95. hexformat       equ  $
  96. hexaddrhi       dw   0
  97. hexaddrlo       dw   0
  98.                 db   ':0  '
  99. hexdata         dw   18 dup(0) 
  100. hexdataend      db   '*$'
  101. hexend          db   '*'
  102. crlf            db   cr,lf,'$'
  103. indent          db   5 dup(' '),'$'
  104.  
  105. asciizl         proc near              ;string, length in CX
  106.                                        ; at ES:DI searched for 0h
  107.                                        ;new length in CX
  108.                 push  ax
  109.                 xor   al,al            ;search for zero
  110.                 call  charstrl
  111.                 pop   ax
  112.  
  113.                 ret
  114.  
  115. asciizl         endp
  116.  
  117. charstrl        proc  near             ;string length in CX
  118.                                        ;string at ES:DI searched for char in AL
  119.                                        ;new length in CX
  120.                 push  ax
  121.                 push  di               ;save register
  122.  
  123.                 push  cx               ;save cx
  124.                 repnz scasb            ;do search
  125.                 jcxz  charsterror      ;if cx exhausted, may be error
  126. charsthit:
  127.                 mov   ax,cx            ;save count remaining
  128.                 pop   cx               ;restore old cx
  129.                 sub   cx,ax            ;subtract length
  130.                 dec   cx               ;knock off 1 for failed test
  131.                 jcxz  charstnull       ;if zero length, error
  132.                 clc                    ;clear carry flag
  133.                 jmp   charstexit       ;and exit
  134.                 
  135. charsterror:
  136.                 dec   di               ;back up
  137.                 cmp   al,es:[di]       ;check last byte 
  138.                 je    charsthit        ;if what we want, use it
  139.  
  140.                 pop   cx               ;pull off saved cx
  141. charstnull:
  142.                 stc                    ;set error flag
  143. charstexit:     
  144.                 pop   di               ;restore registers
  145.                 pop   ax
  146.                 ret
  147.  
  148. charstrl        endp
  149.  
  150. hextocharlist   db   '0123456789ABCDEF'
  151.  
  152. hextochar       PROC near              ;AL (hex) -> AX (characters)
  153.                 PUSH SI
  154.                 PUSH DX
  155.                 PUSH CX
  156.                 PUSH AX
  157.                 XOR  DX,DX
  158.                 AND  AX,0fh            ;isolate low nibble
  159.                 ADD  AX,offset hextocharlist
  160.                 MOV  SI,AX             ;get address of character
  161.                 MOV  DH,[SI]           ;get character
  162.                 POP  AX
  163.                 AND  AX,0f0h           ;isolate high nibble
  164.                 MOV  CL,4
  165.                 SHR  AX,CL
  166.                 ADD  AX,offset hextocharlist
  167.                 MOV  SI,AX             ;get address of character
  168.                 OR   DL,[SI]           ;get character
  169.                 MOV  AX,DX
  170.                 POP  CX
  171.                 POP  DX
  172.                 POP  SI
  173.                 RET
  174. hextochar       ENDP 
  175.  
  176. Hexline         proc near         ;type paragraph at ES: in hex
  177.                 push si
  178.                 push cx
  179.                 push ax
  180.                 push es
  181.                 pop  ax
  182.                 call hextochar    ;get low byte
  183.                 mov  hexaddrlo,ax
  184.                 push es
  185.                 pop  ax
  186.                 mov  al,ah        ;get high byte
  187.                 call hextochar
  188.                 mov  hexaddrhi,ax
  189.                 xor  si,si
  190.                 mov  di,offset hexdata
  191.                 mov  cx,4
  192. hexparaloop:                      ;loop 4 times per paragraph
  193.                 push cx
  194.                 mov  cx,4
  195. hexwordloop:                      ;loop 4 times per doubleword
  196.                 mov  al,es:[si]
  197.                 call hextochar
  198.                 mov  ds:[di],ax
  199.                 inc  di
  200.                 inc  di
  201.                 inc  si
  202.                 loop hexwordloop 
  203.  
  204.                 mov  byte ptr ds:[di],' '
  205.                 inc  di
  206.                 pop  cx
  207.                 loop hexparaloop
  208.  
  209.                 pop  ax
  210.                 pop  cx
  211.                 pop  si
  212.                 ret
  213. hexline         endp 
  214.  
  215. chartype        proc near          ;type CX bytes at ES:DI if typable
  216.                 stc                ;possible error
  217.                 jcxz chartypeexit  ;if nothing to type, exit
  218.                 push ax
  219.                 push cx
  220.                 push dx
  221.                 push di
  222. chartypeloop:
  223.                 mov  dl,es:[di]
  224.                 cmp  dl,126        ;printer/console
  225. ;               cmp  dl,254        ;console only
  226.                 ja   chartypefix               
  227.                 cmp  dl,31
  228.                 ja   chartypeit
  229.                 jmp  chartypefix   ;printer/c